package com.ithema.reggie.mapper;

import com.ithema.reggie.entity.Setmeal;
import com.ithema.reggie.dto.SetmealDto;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface SetMealMapper {

    //根据类别的id查找套餐总数
    @Select("select * from setmeal where category_id = #{categoryId}")
    List<Setmeal> findByCategoryId(Long categoryId);

    @Insert("insert into setmeal values (null,#{categoryId},#{name},#{price},#{status},#{code},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    @SelectKey(statement = "select last_insert_id()",before = false,resultType = Long.class,keyProperty = "id")
    void save(SetmealDto setmealDto);

    List<Setmeal> finfAll(String name);

    //根据套餐的id，查询状态为1的套餐.
    List<Setmeal> findOnsaleByIds(Long[] ids);

    //根据套餐的id删除套餐
    void batchDelectBySetmealIds(Long[] ids);

    //根据套餐的id查询套餐
    @Select("select * from setmeal where id = #{id}")
    Setmeal findById(Long id);

    //修改套餐
    void update(SetmealDto setmealDto);

    @Select("select * from setmeal where category_id = #{categoryId} and status = #{status}")
    List<Setmeal> findByCategoryIdAndStatus(@Param("categoryId") Long categoryId, @Param("status") Integer status);
}
